﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataTransferObject;
namespace _5ChickDeal.UserControl
{
    public partial class LoginPage : System.Web.UI.UserControl
    {
        DataClassesDataContext db;
        protected void Page_Load(object sender, EventArgs e)
        {
            db = new DataClassesDataContext();
            if (Session["user"] != null)
            {
                Response.Redirect("~/Default.aspx");
            }
            

            if (IsPostBack)
            {
                Sm_Click();
            }
        }

        protected void Sm_Click()
        {
         
            try
            {
                String pass = EncoderPassword.GetMd5Hash(TextBoxPassword.Text);
                var khachhang = db.KhachHangs.Where(k => k.email == TextBoxEmail.Text && k.matkhau==pass).First();
                Session["user"] = khachhang;
                Session["login"] = "5chicks";
                Response.Redirect("~/Default.aspx");
            }

            catch (Exception ex)
            {
                TextBoxError.Text = "Sai tên đăng nhập hoặc mật khẩu";
                
                
            }
        }
    }
}